<template>
  <div
    class="number-container d-flex justify-content-center align-items-center"
  >
    <!-- 减 1 的按钮 -->
    <button type="button" class="btn btn-light btn-sm" @click="cut">-</button>
    <!-- 购买的数量 -->
    <span class="number-box">{{ count }}</span>
    <!-- 加 1 的按钮 -->
    <button type="button" class="btn btn-light btn-sm" @click="add">+</button>
  </div>
</template>

<script>
import bus from "@/components/eventBus.js";
export default {
  data() {
    return {};
  },
  props: {
    count: {
      default: "1",
      type: Number,
    },
    id: {
      default: "",
      type: Number,
    },
  },
  methods: {
    add() {
      const obj = { id: this.id, value: this.count + 1 };
      bus.$emit("addCount", obj);
    },
    cut() {
      const obj = { id: this.id, value: this.count - 1 };
      bus.$emit("cutCount", obj);
    },
  },
};
</script>

<style lang="less" scoped>
.number-box {
  min-width: 30px;
  text-align: center;
  margin: 0 5px;
  font-size: 12px;
}

.btn-sm {
  width: 30px;
}
</style>
